#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

CFLAGS = -Wall -g
CXXFLAGS = -Wall -g
NGINX_LEVELDB_DIR = /usr/share/nginx-leveldb

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
	CXXFLAGS += -O0
else
	CFLAGS += -O2
	CXXFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	cmake . -DCMAKE_BUILD_TYPE="release" -DCMAKE_INSTALL_PREFIX=/usr -DCFLAGS="${CFLAGS}" -DCXXFLAGS="${CXXFLAGS}"
	( cd nginx-1.3.14 && ./configure --prefix=${NGINX_LEVELDB_DIR} \
	                                 --sbin-path=${NGINX_LEVELDB_DIR}/sbin/nginx-leveldb \
	                                 --conf-path=${NGINX_LEVELDB_DIR}/conf/nginx-leveldb.conf \
	                                 --error-log-path=/var/log/nginx-leveldb.log \
	                                 --pid-path=/var/run/nginx-leveldb.pid \
	                                 --lock-path=/var/run/nginx-leveldb.lock \
	                                 --add-module=../ngx_leveldb )
	touch configure-stamp

	# --user=USER                        set non-privileged user for worker processes
	# --group=GROUP                      set non-privileged group for worker processes


build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	( cd nginx-1.3.14 && $(MAKE) )

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) clean
	/bin/sh ClearPackage.sh
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/ctl.
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	( cd nginx-1.3.14 && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install )


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a --sourcedir=$(CURDIR)/debian/tmp
	dh_installman -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a -V
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
